package cn.kuang.service;

import cn.kuang.mapper.UserMapper;
import cn.kuang.pojo.User;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 徽州大都督
 * @date 2020/7/27
 */
@Service
@Transactional
public class UserService {

    @Autowired
    private UserMapper userMapper;


    public User login(User user) {

        QueryWrapper wrapper = new QueryWrapper ();
        wrapper.eq ("username",user.getUsername ());
        wrapper.eq ("password",user.getPassword ());


        User user1 = userMapper.selectOne (wrapper);


        return user1;
    }

    public int register(User user) {

        int row = userMapper.insert (user);
        return row;
    }

    public int findByUsername(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<> ();
        wrapper.eq ("username",username);
        User user = userMapper.selectOne (wrapper);
        if (user!=null){
            return 1;
        }else {
            return 0;
        }
    }
}
